﻿using cma.cimiss.client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SXMeteorological.Data.Utility
{
    public class CimissClient:IDisposable
    {
        private static volatile DataQueryClient _Client;
        private static readonly object _LockObj = new object();

        /// <summary>
        /// 取得DataQueryClient的一个初始化后的实例
        /// </summary>
        public static DataQueryClient Instance
        {
            get
            {
                //如果_Client为空,则创建并初始化
                if (_Client == null)
                {
                    //多线程支持
                    lock (_LockObj)
                    {
                        if (_Client == null)
                        {
                            _Client = new DataQueryClient();
                            _Client.initResources();
                        }
                    }
                }
                return _Client;
            }
        }

        /// <summary>
        /// 释放资源
        /// </summary>
        public void Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

        /// <summary>
        /// 释放资源(虚函数)
        /// </summary>
        /// <param name="disposing"></param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                //释放资源
                Instance.destroyResources();
            }
        }

        /// <summary>
        /// 析构函数
        /// </summary>
        ~CimissClient()
        {
            this.Dispose(false);
        }
    }
}
